package com.trex.lwlsh.dataDeal;

import com.trex.lwlsh.model.CaseModel;
import com.trex.lwlsh.model.ConfigModel;
import com.trex.lwlsh.model.ModuleModel;
import com.trex.lwlsh.model.StepModel;
import com.trex.lwlsh.util.LogUtil;

import java.util.ArrayList;

/**
 * Create by Trex on 2018/1/15
 */
public class CaseStepDeal {


    /**
     * 分解模块
     * @param config
     * @param module
     * @throws Exception
     */
    public void ResolveModule(ConfigModel config, ModuleModel module) throws Exception {
        ArrayList<CaseModel> CaseList=module.getCaseList();
        for (int i=0;i<CaseList.size();i++){
            String caseName=CaseList.get(i).getName();
            String caseLevel=CaseList.get(i).getLevel();
            LogUtil.logs("【用例名称】:"+caseName+"\t【用例等级】:"+caseLevel);
            boolean flag= ResolveCase(config,CaseList.get(i));
            if (flag){//跳过执行
                module.setSkip(1);
            }else {
                System.out.println("CaseList.get(i).getResult()" + CaseList.get(i).getResult());
                if (CaseList.get(i).getResult()) {
                    module.setPass(1);
                } else {
                    module.setFail(1);
                }
            }

        }

    }
    /**
     * 分解用例
     * @param config
     */
    public Boolean ResolveCase(ConfigModel config, CaseModel cs) throws Exception {
        Boolean isSkip=false;
        String caseLevel=cs.getLevel();
        ArrayList<StepModel> stepList= cs.getStepList();
        LogUtil.logs("【用例等级】:"+config.getRunLevel());
        if(config.getRunLevel().contains(caseLevel)){//判断该用例是否需要执行，不需要就跳过
            ResolveStep(cs,stepList);
            cs.setStepCount(stepList.size());
        }else{
            LogUtil.logs("这个用例不需要执行");
            isSkip=true;
        }
        return  isSkip;
    }

    /**
     * 执行步骤
     * @param cs
     * @param stepList
     * @throws Exception
     */
    public void ResolveStep(CaseModel cs, ArrayList<StepModel> stepList) throws Exception {
        for(int i=0;i<stepList.size();i++){

              String StepName=stepList.get(i).getName();
              LogUtil.logs("【步骤名称】:"+StepName);
              //获取每步的返回值
              GetResponse response=new GetResponse();
              //每步的返回值赋值
              stepList.get(i).setResponse(response.GetResponse(stepList.get(i)));
              //根据每步的返回值然后去断言每步结果是否一致
              response.GetResponse(stepList.get(i));
              Inspectoscope check=new Inspectoscope();
              check.checkValue(cs, stepList.get(i));
              System.out.println("："+stepList.get(i).getTransfer());
              if(stepList.get(i).getTransfer()!=null){  //判断是否需要提取参数
                   ParametersFactory.GetParameter(stepList.get(i));
              }

        }
    }







}
